﻿using System;
using System.Web.Configuration;
using System.Data;

public partial class manager_taskaudit_view : System.Web.UI.Page
{
    public int taskid = 0;
    DBHelper db = new DBHelper(WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        taskid = Convert.ToInt32(Request.QueryString["taskid"]);
        Edit_Id.Value = taskid.ToString();
        if (!IsPostBack)
        {
            loadEditData(taskid);
        }
    }
    private void loadEditData(int sid)
    {
        string sql = "select * from v_A_Task where id=" + sid;
        DataTable dt = db.getList(sql);
        string type = "0";
        if (dt.Rows.Count == 1)
        {
            type = dt.Rows[0]["type"].ToString();
            txt_title.Value = dt.Rows[0]["title"].ToString();
            txt_ms.Value = dt.Rows[0]["detail"].ToString();
            txt_fb_username.Value = dt.Rows[0]["fb_username"].ToString();
            txt_rq_start.Value = Convert.ToDateTime(dt.Rows[0]["rq_start"].ToString()).ToString("yyyy-MM-dd");
            txt_rq_yjs.Value = Convert.ToDateTime(dt.Rows[0]["rq_yjs"].ToString()).ToString("yyyy-MM-dd");
            txt_rq_sjs.Value = Convert.ToDateTime(dt.Rows[0]["rq_sjs"].ToString()).ToString("yyyy-MM-dd");
            ys_psid_mc.Value = dt.Rows[0]["ys_psid_mc"].ToString() + "|" + dt.Rows[0]["ys_psid_UserName"].ToString();
            eval_ps_mc.Value = dt.Rows[0]["eval_ps_mc"].ToString();
            eval_parps_mc.Value = dt.Rows[0]["eval_parps_mc"].ToString();
            eval_deptps_mc.Value = dt.Rows[0]["eval_deptps_mc"].ToString();
            txt_bz_js.Value = dt.Rows[0]["bz_js"].ToString();

            switch (dt.Rows[0]["state"].ToString())
            {
                case "0":
                    ddlIsUsing.Value = "任务作废，无需执行。";
                    Button1.Visible = false;

                    break;
                case "1":
                    ddlIsUsing.Value = "任务还未被接受，请接受任务开始执行。";
                    Button1.Visible = true;

                    break;
                case "2":
                    ddlIsUsing.Value = "任务执行中还未完成，请尽快完成任务。";
                    Button1.Visible = false;

                    break;
                case "3":
                    ddlIsUsing.Value = "任务已执行完毕，等待验收。";
                    Button1.Visible = true;

                    break;
                case "4":
                    ddlIsUsing.Value = "任务已审核";
                    txt_bz_ys.Value = dt.Rows[0]["bz_ys"].ToString();
                    ddl_point_temp.SelectedValue = dt.Rows[0]["Gp"].ToString();
                    txt_bz_ys.Disabled = true;
                    Button1.Visible = false;

                    break;

            }



        }
        DataTable dt2 = db.getList("SELECT point,('['+RTRIM(CONVERT(char(10),point))+']'+mc) as mc FROM dict_point_temp where isusing=1 and type='" + type + "'");
        ddl_point_temp.DataSource = dt2;
        ddl_point_temp.DataTextField = "mc";
        ddl_point_temp.DataValueField = "point";
        ddl_point_temp.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string taskid = Edit_Id.Value;
        string userName = Session[AppConfig.SESSION_USER_NAME].ToString();
        string point = ddl_point_temp.SelectedValue;
        string bz_ys = txt_bz_ys.Value;
        int i = 0;
        if (taskid != "0")
        {
            string sql = "update A_Task set [state]=4,GP=" + point + ",bz_ys=N'" + bz_ys + "  验收人:" + userName + "' where id=" + taskid + " and [state]=3";
            i = db.executeNoneQuery(sql);
        }
        if (i > 0)
        {
            Response.Write(CommonHelper.alertMsgAndRedirect("任务已经验收", "Default.aspx"));
        }
        else
        {
            Response.Write(CommonHelper.alertMsgAndRedirect("任务验收失败请核对信息", "Default.aspx"));
        }
    }


}